home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
Source
/
DBL Pascal Library
/
DefProcs
/
PopUp
/
PopUpTest.p
< prev
next >
Wrap
Text File
|
1992-06-05
|
6KB
|
249 lines
program PopUpTest;
const
dialogID = 128;
firstMenu = 2; {item numbers}
secondMenu = 3;
hideSecond = 4;
disableControl = 5;
disableMenu = 6;
resetMenu = 7;
speedLabel = 8;
speedTE = 9;
speedMenu = 10;
ctlTitleMenu = 11;
altCTitle = 12;
invisibleMenu = 13;
frameItem = 14;
emptyMenu = 15;
reportItem = 16;
var
theDialog: DialogPtr;
itemHit: Integer;
i: Integer;
theEvent: EventRecord;
pt: Point;
theMenu: MenuHandle;
function GetControlHandle (item: Integer): ControlHandle;
var
kind: Integer;
h: Handle;
r: Rect;
begin
GetDItem(theDialog, item, kind, h, r);
if BAND(kind, $FC) = ctrlItem then
GetControlHandle := ControlHandle(h)
else
GetControlHandle := nil;
end;
function FilterProc (dlg: DialogPtr; var evt: EventRecord; var itemHit: Integer): Boolean;
begin
FilterProc := False;
theEvent := evt;
end;
procedure DrawFrame (theWindow: WindowPtr; itemNo: Integer);
var
itemType: Integer;
itemHandle: Handle;
itemRect: Rect;
begin
PenNormal;
GetDItem(theWindow, itemNo, itemType, itemHandle, itemRect);
FrameRect(itemRect);
end;
procedure SetUserItem (theWindow: WindowPtr; itemNo: Integer; theProc: ProcPtr);
var
itemType: Integer;
itemHandle: Handle;
itemRect: Rect;
begin
GetDItem(theWindow, itemNo, itemType, itemHandle, itemRect);
SetDItem(theWindow, itemNo, itemType, Handle(theProc), itemRect);
end;
procedure ReportControl (theDialog: DialogPtr; item: Integer);
var
aString: Str255;
value: Integer;
hiByte: Integer;
mString: Str255;
loByte: Integer;
iString: Str255;
itemKind: Integer;
itemHandle: Handle;
itemRect: Rect;
itemRgn: RgnHandle;
begin
NumToString(item, aString);
value := GetCtlValue(GetControlHandle(item));
hiByte := BSR(value, 8);
loByte := BAND(value, $FF);
NumToString(hiByte, mString);
NumToString(loByte, iString);
ParamText(aString, mString, iString, '');
GetDItem(theDialog, reportItem, itemKind, itemHandle, itemRect);
itemRgn := NewRgn;
RectRgn(itemRgn, itemRect);
UpdtDialog(theDialog, itemRgn);
DisposeRgn(itemRgn);
end;
procedure RecursiveGetMenu (menuH: MenuHandle);
var
i: Integer;
cmd, mark: Char;
begin
if menuH <> nil then
begin
InsertMenu(menuH, -1);
for i := 1 to CountMItems(menuH) do
begin
GetItemMark(menuH, i, mark);
GetItemCmd(menuH, i, cmd);
if cmd = CHR($1B) then
RecursiveGetMenu(GetMenu(ORD(mark)));
end;
end;
end;
type
popupPrivateData = record
mHandle: MenuHandle;
mID: Integer;
end;
popupPrivateDataPtr = ^popupPrivateData;
popupPrivateDataHdl = ^popupPrivateDataPtr;
function GetDPopUpMenuID (item: Integer): Integer;
begin
GetDPopUpMenuID := popupPrivateDataHdl(GetControlHandle(item)^^.contrlData)^^.mID;
end;
procedure GetDPopUpMenu (item: Integer);
var
menuID: Integer;
menuH: MenuHandle;
begin
menuID := GetDPopUpMenuID(item);
menuH := GetMenu(menuID);
RecursiveGetMenu(menuH);
end;
function NewDPopUpMenu (item: Integer; title: Str255): MenuHandle;
var
menuID: Integer;
menuH: MenuHandle;
begin
menuID := GetDPopUpMenuID(item);
menuH := NewMenu(menuID, title);
if menuH <> nil then
InsertMenu(menuH, -1);
NewDPopUpMenu := menuH;
end;
begin
theDialog := GetNewDialog(dialogID, nil, POINTER(-1));
SetPort(theDialog);
GetDPopUpMenu(firstMenu);
GetDPopUpMenu(secondMenu);
{$IFC True}
theMenu := NewDPopUpMenu(speedMenu, '');
AppendMenu(theMenu, '123');
AppendMenu(theMenu, '456');
{$ELSEC}
GetDPopUpMenu(speedMenu);
{$ENDC}
GetDPopUpMenu(ctlTitleMenu);
GetDPopUpMenu(invisibleMenu);
GetDPopUpMenu(emptyMenu);
SetUserItem(theDialog, frameItem, @DrawFrame);
TextFont(geneva); {Try different fonts and sizes to see how useWFont variant works…}
TextSize(9);
ShowWindow(theDialog);
for i := 1 to 3 do {Have to do this to synchronize TE items to the window font!}
if EventAvail(everyEvent, theEvent) then
;
with DialogPeek(theDialog)^.textH^^ do
begin
txFont := theDialog^.txFont;
txSize := theDialog^.txSize;
end;
InitCursor;
repeat
ModalDialog(@FilterProc, itemHit);
case itemHit of
firstMenu, secondMenu, speedMenu, ctlTitleMenu, emptyMenu:
ReportControl(theDialog, itemHit);
frameItem:
begin
pt := theEvent.where;
GlobalToLocal(pt);
MoveControl(GetControlHandle(invisibleMenu), pt.h, pt.v);
i := TrackControl(GetControlHandle(invisibleMenu), pt, POINTER(-1));
ReportControl(theDialog, invisibleMenu);
end;
hideSecond:
begin
SetCtlValue(GetControlHandle(hideSecond), 1 - GetCtlValue(GetControlHandle(hideSecond)));
if GetCtlValue(GetControlHandle(hideSecond)) = 1 then
HideControl(GetControlHandle(secondMenu))
else
ShowControl(GetControlHandle(secondMenu));
end;
disableControl:
begin
SetCtlValue(GetControlHandle(disableControl), 1 - GetCtlValue(GetControlHandle(disableControl)));
if GetCtlValue(GetControlHandle(disableControl)) = 1 then
HiliteControl(GetControlHandle(secondMenu), 255)
else
HiliteControl(GetControlHandle(secondMenu), 0);
if GetCtlValue(GetControlHandle(disableControl)) = 1 then
HiliteControl(GetControlHandle(speedMenu), 255)
else
HiliteControl(GetControlHandle(speedMenu), 0);
end;
disableMenu:
begin
SetCtlValue(GetControlHandle(disableMenu), 1 - GetCtlValue(GetControlHandle(disableMenu)));
if GetCtlValue(GetControlHandle(disableMenu)) = 1 then
DisableItem(GetMenu(GetDPopUpMenuID(secondMenu)), 0)
else
EnableItem(GetMenu(GetDPopUpMenuID(secondMenu)), 0);
Draw1Control(GetControlHandle(secondMenu)); {Control manager has to be informed…}
end;
resetMenu:
begin
SetCtlValue(GetControlHandle(secondMenu), 3);
ReportControl(theDialog, secondMenu);
end;
altCTitle:
begin
SetCtlValue(GetControlHandle(altCTitle), 1 - GetCtlValue(GetControlHandle(altCTitle)));
if GetCtlValue(GetControlHandle(altCTitle)) = 0 then
SetCTitle(GetControlHandle(ctlTitleMenu), 'T1:')
else
SetCTitle(GetControlHandle(ctlTitleMenu), 'Alt T2:');
end;
otherwise
;
end;
until ItemHit = OK;
DisposDialog(theDialog);
end.